public class test6 {
    //力扣 209 长度最小的子数组
    public static void main(String[] args) {
        int[] arr = {1,1,1,1,1,1,1,1};
        int target = 11;
        int i = minSubArrayLen(target, arr);
        System.out.println(i);

    }

    private static int minSubArrayLen(int target, int[] nums) {
        //1.定义两个指针，窗口的左右端点
        int right = 0;
        int left = 0;
        int sum = 0;
        int minlen = nums.length+1;
        //2.
        while (right < nums.length) {

            sum+=nums[right];

            while (sum >= target){
                minlen = Math.min( right-left+1,minlen);
                sum-=nums[left++];

            }
            right++;

        }


        return minlen==nums.length+1? 0:minlen;
    }
}
